<template>
  <div>
    <!-- 表格 -->
    <subTable
      :table-label="tableLabel"
      :table-data="couponList.slice((currentpage-1)*pagesize,currentpage*pagesize)"
    />
    <!-- 分页组件 -->
    <pagination
      :total="total"
      :current-page="currentpage"
      :page-size="pagesize"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
    />
  </div>
</template>

<script>
import SubTable from '@/components/Eltable'
import Pagination from '@/components/Pagination' // 分页组件

export default {
  components: {
    Pagination,
    SubTable
  },
  props: {
    couponList: {
      type: Array,
      default: () => {
        return []
      }
    }
  },
  data() {
    return {
      total: 0,
      currentpage: 1,
      pagesize: 10,
      tableLabel: [
        {
          label: '编号', width: '', prop: 'id'
        }, {
          label: '优惠码', width: '', prop: 'code'
        }, {
          label: '状态', width: '', prop: 'status'
        }, {
          label: '使用者', width: '', prop: 'userName'
        }, {
          label: '订单信息', width: '', prop: 'orderId'
        },
        {
          label: '原价', width: '', prop: 'originalPrice'
        },
        {
          label: '实付', width: '', prop: 'actualPayment'
        },
        {
          label: '领取时间', width: '', prop: 'receiveTime'
        },
        {
          label: '使用时间', width: '', prop: 'orderTime'
        }
      ],
      tableData: []
    }
  },
  updated() {
    this.total = this.couponList.length
  },
  methods: {
    handleSizeChange(val) {
      this.currentpage = 1
      this.pagesize = val.value
      if (this.pagesize >= 20) {
        scrollTo(50, 800)
      }
    },
    handleCurrentChange(val) {
      this.currentpage = val.value
      if (this.pagesize >= 20) {
        scrollTo(50, 800)
      }
    }
  }
}
</script>

<style scoped>

</style>
